{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<script>
    function no_pic(obj) {
        obj.setAttribute("src", "/Public/Images/acp/nopicture.jpg");
    }
</script>

<div class="tablesWrap">
    <div class="tables-searchbox">
        <form method="post">
            <span class="tbs-txt">用户名称：</span>
            <input type="text" name="linkman" value="{$linkman}">

            <span class="tbs-txt">联系方式：</span>
            <input type="text" name="linkphone" value="{$linkphone}">

            <div class="mgt10">
                <span class="tbs-txt">申请时间：</span>
                <input type="text" autocomplete="off" class="Wdate" name="start_date" value="{$start_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd H:mm'})">
                <span class="tbs-txt">至</span>
                <input type="text" autocomplete="off" class="Wdate" name="end_date" value="{$end_date|date_format:'%Y-%m-%d'}"  onclick="WdatePicker({ dateFmt:'yyyy-MM-dd H:mm'})">
                <button type="submit" class="btn"><i class="gicon-search"></i>搜索</button>
            </div>

        </form>
    </div>
    <!-- end tables-searchbox -->
    <table class="wxtables">
        <colgroup>
            {if $opt == 'passed'}<col width="5%">{/if}
            <col width="8%">
            <col width="8%">
            <col width="10%">
            <col width="10%">
            <col width="6%">
            <col width="15%">
            <col width="6%">
            <col width="6%">
            <col width="10%">
            <col width="20%">
        </colgroup>
        <thead>
        <tr>
            {if $opt == 'passed'}<td>选择</td>{/if}
            <td>联系人</td>
            <td>联系方式</td>
            <td>预约时间</td>
            <td>预定单位</td>
            <td>与会人数</td>
            <td>备注</td>
            <td>所属场地</td>
            <td>支付状态</td>
            <td>添加时间</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {foreach from=$site_order_list item=item name=list}
        <tr>
            {if $opt == 'passed'}<td><input type="checkbox" class="checkbox" value="{$item.site_order_id}" name="a[]"></td>{/if}
            <td>{$item.linkman}</td>
            <td>{$item.linkphone}</td>
            <td>{$item.order_time|date_format:"%Y-%m-%d"} {foreach from = $item.time_arr item = range}{$range}{/foreach}</td>
            <td>{$item.order_company}</td>
            <td>{$item.order_num}</td>
            <td>{$item.mark}</td>
            <td>{$item.site_name}</td>
            <td>{$item.state}</td>
            <td>{$item.addtime|date_format:"%Y-%m-%d %H:%M:%S"}</td>
            <td>
                <a href="/AcpSite/get_site_list/site_id/{$item.site_id}" class="btn" title="查看场地">查看场地</a>
                {if $opt == 'not_pass'}
                <a href="/AcpSiteOrder/detail_bypass_site_order/site_order_id/{$item.site_order_id}" class="btn" title="订单详情">订单详情</a>
                <a href="javascript:;" class="btn" onclick="set_check({$item.site_order_id},1)">同意</a>
                <a href="javascript:;" class="btn" onclick="set_check({$item.site_order_id},2)">拒绝</a>
                {/if}
                {if $opt == 'passed'}
                <a href="/AcpSiteOrder/detail_passed_site_order/site_order_id/{$item.site_order_id}" class="btn" title="订单详情">订单详情</a>
                {if $item.pay_status == 1}
                <!-- <a href="javascript:;" class="btn" onclick="refund({$item.site_order_id})">退款</a> -->
                {/if}
                <a href="javascript:;" class="btn" onclick="delete_obj({$item.site_order_id})">删除</a>
                {/if}
            </td>
        </tr>
        {foreachelse}
        <tr><td colspan="10">没有找到任何记录</td></tr>
        {/foreach}
        </tbody>
    </table>
    <!-- end wxtables -->
    <div class="tables-btmctrl clearfix">
        <div class="fl">
            {if $opt == 'passed'}
            <a href="javascript:Select()" class="btn btn-blue">全选</a>
            <a href="javascript:Cancel()" class="btn btn-blue">取消</a>
            <a href="javascript:;" class="btn btn-blue " onclick="batch_delete_obj()">删除</a>
            {/if}
        </div>
        <div class="fr">
            <div class="paginate">
                {$page_str}
            </div>
            <!-- end paginate -->
        </div>
    </div>
    <!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap -->
{/block}

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script src="__ACPJS__/acp_item.js?version={$version}"></script>
<script src="__JS__/front/jquery.showLoading.min.js?version={$version}"></script>
<script src="__JS__/clipboard.min.js"></script>
<link rel="stylesheet" href="__CSS__/front/showLoading.css?version={$version}">
{literal}
<script>
    //全选
    function Select(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=true;
        }
    }
    //取消全选
    function Cancel(){
        var sel=document.getElementsByName("a[]");
        for(var i=0;i<sel.length;i++){
            sel[i].checked=false;
        }
    }

</script>
<script>

    function set_check(obj_id,type)
    {
        $.jPops.confirm(
                {
                    title:"提示",
                    content:"您确定要执行吗？",
                    okBtnTxt:"确定",
                    cancelBtnTxt:"取消",
                    callback:function(r)
                    {
                        if(r)
                        {
                            $.post('/AcpSiteOrder/set_check', {"obj_id":obj_id,"type":type}, function(data, textStatus)
                            {
                                if (data.code= 1)
                                {
                                    alert(data.msg);
                                    location.reload();
                                }
                                else
                                {
                                    alert(data.msg);
                                }
                            });
                        }
                        return true;
                    }
                });
    }

    function delete_obj(obj_id)
    {
        $.jPops.confirm(
                {
                    title:"提示",
                    content:"您确定要删除这条数据吗？",
                    okBtnTxt:"确定",
                    cancelBtnTxt:"取消",
                    callback:function(r)
                    {
                        if(r)
                        {
                            $.post('/AcpSiteOrder/delete_site_order', {"obj_id":obj_id}, function(data, textStatus)
                            {
                                if (data == 'success')
                                {
                                    alert('恭喜您，删除成功！');
                                    location.reload();
                                }
                                else
                                {
                                    alert('对不起，删除失败！');
                                }
                            });
                        }
                        return true;
                    }
                });
    }

    function batch_delete_obj()
    {
        $.jPops.confirm(
                {
                    title:"提示",
                    content:"您确定要删除这些数据吗？",
                    okBtnTxt:"确定",
                    cancelBtnTxt:"取消",
                    callback:function(r)
                    {
                        if(r)
                        {
                            var obj_ids = '';
                            var count = 0;
                            $('input[name="a[]"]:checked').each(function(){
                                count ++;
                                obj_ids += $(this).val() + ',';
                            });

                            if (!count)
                            {
                                alert('对不起，请选择至少一项进行删除！');
                                return;
                            }

                            obj_ids = obj_ids.substr(0, obj_ids.length - 1);

                            $.post('/AcpSiteOrder/batch_delete_site_order', {"obj_ids":obj_ids}, function(data, textStatus)
                            {
                                if (data == 'success')
                                {
                                    alert('恭喜您，删除成功！');
                                    location.reload();
                                }
                                else
                                {
                                    alert('对不起，删除失败！');
                                }
                            });
                        }
                        return true;
                    }
                });
    }


    //退款
    function refund(order_id){
        
        $.jPops.confirm(
            {
                title: "提示",
                content: "您确定要执行该操作吗？",
                okBtnTxt: "确定",
                cancelBtnTxt: "取消",
                callback: function (r) {
                    if (r) {
                        $.ajax({
                            url:'/AcpSiteOrder/refund',
                            type:'post',
                            data:{order_id:order_id},
                            success:function(r){
                                if(r.code == 0){
                                    alert(r.msg);
                                    location.reload();
                                }else if(r.code == 2){
                                    window.location.href = r.link
                                }else{
                                    alert(r.msg);
                                }
                            }
                        })
                    }
                    return true;
                }
            });
            
            

    }
</script>
{/literal}
{/block}
